package jp.heartdokyun.model.component;

public class BehaviorB extends Behavior {

	private double s = 1d;
	private double a = 1d;
	private boolean mr = true;
	private int dir = 1;
	private double rad;
	private double angle;
	private int distance,initX,initY;
	
	public BehaviorB(int speed, int angleSpeed, int distance,int initx, int inity) {
		super(speed, angleSpeed, distance,initx,inity);
	}
	@Override
	protected void _init() {
		this.setAngle((Double) Math.random() * 2);
		this.setInitX(170);
	}

	@Override
	public void caliculateNextPosition(int currentX, int currentY, int width, int height, int bitmapWidth, int bitmapHeight) {
		this.setAngle(this.getAngle() + getAngleSpeed());
		if (angle > 2d) angle = angle - 2d;
		if (angle < 0d) angle = angle + 2d;

		if (this.isOutOfFrameWidth(currentX, width, bitmapWidth)) {
			//this.setAngle(1d - this.getAngle());
			this.setAngle(1d - this.getAngle());
			this.setAngleSpeed(- this.getAngleSpeed());
			
		}
		if (this.isOutOfFrameHeight(currentY, height, bitmapHeight)) {
			this.setAngle(2d - this.getAngle());		
			this.setAngleSpeed(- this.getAngleSpeed());
		}
		//left
		if (this.isOutOfFrameHeightLeft(currentY, width, bitmapWidth)) {
			if(mr)
			{
				mr = false;
			}
			else
			{
				mr = true;
			}
			
		}
		//right
		if (this.isOutOfFrameHeightRight(currentY, width, bitmapWidth)) {
			if(!mr)
			{
				mr = true;
			}
			else
			{
				mr = false;
			}
		}

		if(mr)
		{
			dir = 1;
		}
		else
		{
			dir = -1;
		}
		a += this.getSpeed();
		s += dir*this.getSpeed();
		rad = Math.toRadians(a);

		setNextY((int)s);
		setNextX(currentX + (int) ( Math.cos(rad)*this.getDistance()));
		//org
		//setNextX(currentX + (int) (this.getSignX() * this.getSpeed() * Math.cos(angle * Math.PI)));
		//setNextY(currentY + (int) (this.getSignY() * this.getSpeed() * Math.sin(angle * Math.PI)));
	}

	public double getAngle() {
		return angle;
	}

	public void setAngle(double angle) {
		this.angle = angle;
	}

}